From 52e91db180af60a2f1b34eecc9434e11a255e36f Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Tue, 10 Jan 2006 14:37:25 +0000 Subject: [PATCH] Proactively check for NULL strings passed into xc_linux_build. Either DTRT or return error if detected. A NULL cmdline, for example, would currently generate a segfault. Signed-off-by: Ben Thomas --- tools/libxc/xc_linux_build.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/libxc/xc_linux_build.c b/tools/libxc/xc_linux_build.c index a48ecd45bd..6a7a0369fc 100644 --- a/tools/libxc/xc_linux_build.c +++ b/tools/libxc/xc_linux_build.c @@ -693,8 +693,11 @@ static int setup_guest(int xc_handle, start_info->mod_start = vinitrd_start; start_info->mod_len = initrd_len; } - strncpy((char *)start_info->cmd_line, cmdline, MAX_GUEST_CMDLINE); - start_info->cmd_line[MAX_GUEST_CMDLINE-1] = '\0'; + if (cmdline != NULL) { + strncpy((char *)start_info->cmd_line, cmdline, MAX_GUEST_CMDLINE); + start_info->cmd_line[MAX_GUEST_CMDLINE-1] = '\0'; + } else + start_info->cmd_line[0] = '\0'; munmap(start_info, PAGE_SIZE); /* shared_info page starts its life empty. */ @@ -755,7 +758,8 @@ int xc_linux_build(int xc_handle, goto error_out; } - if ( (image = xc_read_kernel_image(image_name, &image_size)) == NULL ) + if ( (image_name == NULL) || + ((image = xc_read_kernel_image(image_name, &image_size)) == NULL) ) goto error_out; if ( (ramdisk_name != NULL) && (strlen(ramdisk_name) != 0) ) -- 2.30.2